<?php
//Start de sessie
session_start();

ob_start();


// Database connection
include 'includes/connect.php';

// Encodeer het id-nummer uit de URL
if(isset($_GET['id']) && is_numeric($_GET['id']))
{
    $id=$_GET['id'];
    // Retrieve all the data from the table
    $result = mysql_query("SELECT productnaam FROM product WHERE productid='". $_GET['id'] ."'")
    or die(mysql_error());
}
else
{
        	header('Location: index.php');
}

// store the record of the table into $row
$row = mysql_fetch_array( $result );
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title><?php echo $row['productnaam']; ?></title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link type="text/css" href="css/pagination.css" rel="stylesheet" />
  <link rel="stylesheet" href="css/reset.css" type="text/css" />
  <link rel="stylesheet" href="css/960.css" type="text/css" />
  <link rel="stylesheet" href="css/text.css" type="text/css" />
  <link type="text/css" href="css/tablesorter.css" rel="stylesheet" />
  <link type="text/css" href="css/sunny/jquery-ui-1.8.custom.css" rel="stylesheet" />
  <link type="text/css" href="css/jquery.autocomplete.css" rel="stylesheet" />
  <link type="text/css" href="css/style.css" rel="stylesheet" />
  <link type="text/css" href="css/accmenu.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.4.2.min.js">
</script>
<script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js">
</script>
<script type="text/javascript" src="js/jquery.tablesorter.js">
</script>
<script type="text/javascript" src="js/jquery.autocomplete.min.js">
</script>
<script type="text/javascript" src="js/menu.js">
</script>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function()
    {
        $("#producttable").tablesorter();
        $("#searchtext").autocomplete("autocomplete.php");
        $("#searchtext").result(function(event, data, formatted) {
			$("#searchform").trigger('submit');
	    });

        $("#loginbox").dialog({
			autoOpen: false,
			height: 230,
			width: 350,
			modal: true,
            buttons: {
				'Login': logincall,
				Cancel: function() {
					$(this).dialog('close');
				}
                }
		});

        $("#login button").button({
            icons: {
                primary: 'ui-icon-locked'
            }
        })
        .click(function() {
				$('#loginbox').dialog('open');
			});
        $("#register button").button();
        $("#logout button").button();
        $("#shoppingcart button").button();
    }
);

function logincall() {
      $.ajax({
      type: "POST",
      url: "login.php",
      data: $("#loginform").serialize(),
      dataType: "text",
      complete: function() {
        $(this).dialog('close');
        $(location).attr('href', "login.php");
      }
    });
  return;
}

//]]>
</script>
</head>

<body>
  <div class="container_12">
    <div id="header" class="grid_12">
      <div class="grid_5 prefix_7 alpha omega">
        <form id="searchform" name="searchform" method="get" action="search.php">
          <input type="text" name="q" id="searchtext" /> <button type="submit" id=
          "searchbutton"></button>
        </form>

        <div id="demo">
          <ul>
            <?php if(!empty($_SESSION['klantid'])){?>
            <li id="logout"><a href="logout.php"><button>Log Out</button></a></li>
            <li id="shoppingcart"><a href="view_cart.php"><button>Winkelwagen</button></a></li>
            <?php } else {?>
            <li id="login"><button>Log In</button></li>
            <li id="register"><a href="register.php"><button>Registreer</button></a></li>
            <?php } ?>
          </ul>


        </div>
        <?php if(!empty($_SESSION['klantid'])){?>
                        <p id="klantwelkom">Welkom <b><a href="account.php"><?php echo $_SESSION['fullname']; ?></a></b>&nbsp;&nbsp;
                        </p><?php } else { ?>
                        <p id="klantwelkom"><a href="forgot_pass.php">Wachtwoord vergeten?</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
                        <?php } ?>
      </div>

      <div class="clear"></div>
    </div>

    <div class="clear"></div>

    <div class="grid_12 spacer"></div>

    <div class="clear"></div>

    <div id="menu" class="grid_2">

          <?php
          include_once 'temp/menu_filler.php';
          ?>


    </div>

    <div id="mainarea" class="grid_7">
        <div id="tableholder">

                  <?php
                  // Database connection
                  include 'includes/connect.php';

                  // Encodeer het id-nummer uit de URL
                  if(isset($_GET['id']) && is_numeric($_GET['id']))
                  {
                      $id=$_GET['id'];
                      // Retrieve all the data from the table
                      $result = mysql_query("SELECT * FROM product WHERE productid='".$id."'")
                      or die(mysql_error());
                  }
                  else
                  {
                          	header('Location: index.php');
                  }
                  ###########################################################################################

                  $action 	= $_POST['winkelwagen'];


                  if(!empty($action))
                  {
                  	if(isset($_SESSION['winkelwagen']["$id"]))
                  	{
                  		$_SESSION['winkelwagen']["$id"]=$_SESSION['winkelwagen']["$id"]+$action;
                  	} else {
                  		$_SESSION['winkelwagen']["$id"] = $action;
                  	}
                  	header("Location: view_cart.php");
                  }

                  ###########################################################################################



                  ###########################################################################################

                  $action2 	= $_POST['wishlist'];
                  if(!empty($action2))
                  {
                    // Retrieve wishlist
                    $q1 = mysql_query("SELECT wishlist FROM klant WHERE klantid='".$_SESSION['klantid']."'")
                    or die(mysql_error());
                    $r1 = mysql_fetch_array( $q1 );
                    $neww = $r1['wishlist'];

                    if($neww != NULL)
                    {
                        // dit id toevoegen aan de database
                        $neww = $neww.','.$id;
                    }
                    else
                    {
                        $neww = ','.$id;
                    }

                    $test = "UPDATE klant SET wishlist='".$neww."' WHERE klantid='".$_SESSION['klantid']."'";
                    $q2 = mysql_query($test)
                    or die(mysql_error());

                  	header("Location: view_wishlist.php");
                  }

                  ###########################################################################################



                  ###########################################################################################

                  $action3 	= $_POST['stdlijst'];
                  if(!empty($action3))
                  {
                    // Retrieve stdlijst
                    $q2 = mysql_query("SELECT stdlijstje FROM klant WHERE klantid='".$_SESSION['klantid']."'")
                    or die(mysql_error());
                    $r2 = mysql_fetch_array( $q2 );
                    $news = $r2['stdlijstje'];

                    $news = unserialize($news);

                    // id en aantal toevoegen aan de database
                    $news["$id"] = $action3;

                    $news = serialize($news);

                    $test2 = "UPDATE klant SET stdlijstje='".$news."' WHERE klantid='".$_SESSION['klantid']."'";
                    $q2 = mysql_query($test2)
                    or die(mysql_error());

                  	header("Location: view_stdlijst.php");
                  }

                  ###########################################################################################





                  // store the record of the table into $row
                  $row = mysql_fetch_array( $result );


                  // Print out the contents of the entry

                  $lvb=$row['voorraad'];
                  
                  if($id<='166526')
                  {
                    $img='productimages/'.$id.'.jpg';
                  }
                  else
                  {
                    $img=$row['img'];
                  }



                  $now=mktime();





                  echo "<center>";
                  echo "<h3><b>".$row['productnaam']."</b></h3>";

                  echo "<img src=\" img/$img\" width=\"125\" height=\"125\">";
                  echo "<br />";
                  echo "<br />";

                  echo "<table border='0'>";

                  if ($row['Core omschrijving'] !== NULL)
                  {
                        echo "<tr><td><b>Omschrijving:</b> ".strip_tags($row['Core omschrijving'])."</tr></td>";
                  }
                  else
                  {
                        echo "<tr><td><b>Omschrijving:</b> ".strip_tags($row['omschrijving'])."</tr></td>";
                  }

                  echo "<tr><td><b>Categorie:</b> <a href='cat.php?c=".$row['categorie']."'>".$row['categorie']."</a></tr></td>";

                  echo "<tr><td><b>Status:</b> ";
                  if($lvb>'0')
                  {
                    echo "Op voorraad"."</tr></td>";
                  }
                  else
                  {
                    echo "Tijdelijk niet op voorraad"."</tr></td>";
                  }

                  if ($row['begindate'] < $now && $row['enddate'] > $now )
                  	{
                  		echo "<tr><td><center>Aanbieding! Nu van &euro;<b>".number_format($row['stdprijs'],2)."</b> voor &euro;<b>".number_format($row['Promotieprijs'],2)."</b></center></tr></td>";

                  	}
                  else 
                  	{
                  	  echo "<tr><td><b>Prijs:</b> &euro;".number_format($row['stdprijs'],2)."</tr></td>";
                  	}
                  echo "</table>";

                  // je kan het product alleen in je mandje gooien als het op voorraad is natuurlijk ;)
                  if($lvb>'0')
                  {
                      echo "<form  action=\"product.php?id=".$id."\" method=\"post\">
                      <input name='winkelwagen' type='text' size='3' maxlength='3' value='1' style='text-align:center;'><input type='submit' value='in wagen'></form>";
                  }

                  // alleen ingelogde klanten kunnen van deze opties gebruik maken
                  if(!empty($_SESSION['klantid'])){
                  echo "<form  action=\"product.php?id=".$id."\" method=\"post\">
                  <input name='wishlist' type='hidden' value='1' style='text-align:center;'><input type='submit' value='toevoegen aan wishlist'></form>
                  <form  action=\"product.php?id=".$id."\" method=\"post\">
                  <input name='stdlijst' type='text' size='3' maxlength='3' value='1' style='text-align:center;'><input type='submit' value='pers. boodschappenlijst'></form>";
                  }

                  echo "<br /><center><a href=\" javascript:history.go(-1) \">Ga terug</a></center>";

                  ?>

        </div>
    </div>

    <div id="sidebar" class="grid_3"><div id="tableholder"><?php include 'cart.php'; ?></div></div>

    <div class="clear"></div>

    <div class="grid_12 spacer"></div>

    <div class="clear"></div>
</div>
<div id="loginbox">
                <form action="#" method="POST" id="loginform">
                <br /><p><label for="email">Email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
                <input type="text" value="" name="email" class="text ui-widget-content ui-corner-all" /></p>
                <p><label for="wachtwoord">Wachtwoord:</label>
                <input type="password" value="" name="wachtwoord" class="text ui-widget-content ui-corner-all" /></p>
</form>
</div>
<center>
<!-- Begin Motigo Webstats counter code -->
<a id="mws4736564" href="http://webstats.motigo.com/">
<img width="80" height="15" border="0" alt="Free counter and web stats" src="http://m1.webstats.motigo.com/n80x15.gif?id=AEhGNAHBHVZi00ZSyCakWn8n38NA" /></a>
<script src="http://m1.webstats.motigo.com/c.js?id=4736564&amp;lang=NL&amp;i=3" type="text/javascript"></script>
<!-- End Motigo Webstats counter code -->
</center>
<br />

</body>
</html>